home *** CD-ROM | disk | FTP | other *** search
- Path: rcp6.elan.af.mil!rscernix!danpop
- Newsgroups: comp.lang.c
- Subject: Re: sprintf() question
- Message-ID: <danpop.827968757@rscernix>
- From: danpop@mail.cern.ch (Dan Pop)
- Date: 27 Mar 96 23:19:17 GMT
- References: <31593522.76B3@cbm.com>
- Organization: CERN European Lab for Particle Physics
- NNTP-Posting-Host: ues5.cern.ch
- X-Newsreader: NN version 6.5.0 #7 (NOV)
-
- In <31593522.76B3@cbm.com> Dave Payne <paynedc@cbm.com> writes:
-
- >Question on sprintf():
- >
- >Is it safe, and more importantly, is it ANSI standard, to use sprintf()
- >to print into the same variable? Consider this example:
- >
- >char foo[100] = "foobar";
- >
- >sprintf(foo,"%s%s","the string is",foo);
- >
- >--------------------------------------------
- >
- >Would the resulting string be "the string is foobar", or will this
- >code cause problems because I'm using the same variable (foo) to
- >print to as well as read from?
-
- 4.9.6.5 The sprintf function
-
- Synopsis
-
- #include <stdio.h>
- int sprintf(char *s, const char *format, ...);
-
- Description
-
- The sprintf function is equivalent to fprintf , except that the
- argument s specifies an array into which the generated output is to be
- written, rather than to a stream. A null character is written at the
- end of the characters written; it is not counted as part of the
- returned sum. If copying takes place between objects that overlap,
- the behavior is undefined.
-
- The last phrase answers your question.
-
- Dan
- --
- Dan Pop
- CERN, CN Division
- Email: danpop@mail.cern.ch
- Mail: CERN - PPE, Bat. 31 R-004, CH-1211 Geneve 23, Switzerland
-